package com.baizhi.utils;

import com.baizhi.service.CmfzUserService;
import com.google.gson.Gson;
import io.goeasy.GoEasy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class GoeasyUtil {
    @Autowired
    private CmfzUserService cmfzUserService;

    public void publish() {
//          获取最新的用户数据
            Map map = cmfzUserService.selectBoysAndGirls();
            int boys = (int) map.get("boys");
            int girls= (int) map.get("girls");
            int[] number={boys,girls};

//        转成json
            Gson gson = new Gson();
            String count = gson.toJson(number);

            System.out.println(count);

//        通过goeasy发布
            GoEasy goEasy = new GoEasy( "https://rest-hangzhou.goeasy.io", "BC-c0b38464b66745de9148b11bcb5612dd");
            goEasy.publish("sexcount", count);
    }

}
